//==============================================================================
#ifndef _MODEL_H_
#define _MODEL_H_

#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif

#pragma once
#include "Model.h"
#include "GameServer.h"
#include "concurrent\Runnable.h"
#include "Observable.h"
#include "persistence\SceneRepository.h"
#include "concurrent\CriticalSection.h"
#include "ui\Scene.h"
#include "HRTimer.h"
#include <string>
#include <time.h>
#include <stdio.h>
#include <windows.h>

using namespace std;
using namespace concurrent;

//==============================================================================
class Model : public Runnable
{
public:
	Model(GameServer* server, string sceneName);
	virtual ~Model(void);

	void setScene(Scene* scene);
	Scene* getScene();
	void setIsProcessing(bool flag);
	bool isProcessing(void);
	void setSceneName(string name);
	string getSceneName();
	void setIsSceneStateReady(bool flag);
	bool isSceneStateReady();
	string getSceneBackgroundPath();
	ByteBuffer* getSceneState();
	void setIsReady(bool flag);
	bool isReady();

	void setServer(GameServer* server);
	GameServer* getServer(void);

	void loadSceneGameFiles();
	int addNewTank(string name);
	CriticalSection* getAddNewTankLock();

	int startProcessingUpdates();
	void stopProcessingUpdates();

protected:
	virtual DWORD run(void);
private:
	bool _isProcessing;
	bool _isReady;
	bool _isSceneStateReady;
	GameServer* server;
	Scene* scene;
	ByteBuffer sceneState;
	string sceneName;
	CriticalSection* lock;
	CriticalSection addNewTankLock;
};

#endif
